package com.tf_cut.backend.seller.service;


import com.tf_cut.backend.common.service.CommonServiceImpl;
import com.tf_cut.backend.person.vo.PersonAndAccountVo;
import com.tf_cut.backend.seller.pojo.SellerProject;
import com.tf_cut.backend.seller.repository.SellerProjectRepository;
import com.tf_cut.backend.seller.vo.SellerProjectVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Service
@Transactional
@Slf4j
public class SellerProjectServiceImpl extends CommonServiceImpl<SellerProjectVo, SellerProject, String> implements SellerProjectService {

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private SellerProjectRepository sellerProjectRepository;

    @Autowired
    private com.tf_cut.backend.mapper.SellerProjectMapper sellerProjectMapper;


    @Override
    public List<SellerProjectVo> findProject( String projectName, String startDate, String endDate, Integer havePersonInfo, String personInfoId) {
        return sellerProjectMapper.findSellerProject(projectName,startDate,endDate,havePersonInfo,personInfoId);
    }

    @Override
    public List<SellerProjectVo> findMobileProject(String projectName, String startDate, String endDate, Integer havePersonInfo, String personInfoId) {
        return sellerProjectMapper.findMobileSellerProject(projectName,startDate,endDate,havePersonInfo,personInfoId);
    }

    @Override
    public List<SellerProjectVo> findProjectByVo(SellerProjectVo sellerProjectVo) {
         List<SellerProjectVo> list = sellerProjectMapper.findProjectByVo(sellerProjectVo);
         for(int i= 0; i<list.size();i++){
        	 String[] split = list.get(i).getProjectCode().split(",");
        	 list.get(i).setProjectCode(split[0]);
         }
         return list;
    }

    @Override
    public List<PersonAndAccountVo> findProjectPersonInfoByProjectId(String projectCode) {
        return sellerProjectMapper.findProjectPersonInfoByProjectId(projectCode);
    }

    @Override
    public String qryLastSerial(String orderId) {
        return null;
    }
    
    @Override
    public List<SellerProjectVo> findProjects(String personName,String sellerName,String projectName,String startDate, String endDate) {
        return sellerProjectMapper.findSellerProjects(personName,sellerName,projectName,startDate,endDate);
    }

	@Override
	public SellerProjectVo findByProjectCodeOne(String projectCode) {
		return sellerProjectMapper.findByProjectCodeOne(projectCode);
	}

}
